﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProductKeyManager.Utility
{
    /// <summary>
    /// Static class for getting information about the current user
    /// </summary>
    public static class UserInformation
    {
        /// <summary>
        /// Currents the user.
        /// </summary>
        /// <returns></returns>
        public static string CurrentUser()
        {
            return CurrentUser(false);
        }

        /// <summary>
        /// Currents the user.
        /// </summary>
        /// <param name="withDomain">if set to <c>true</c> [with domain].</param>
        /// <returns></returns>
        public static string CurrentUser(bool withDomain)
        {
            System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent();
            if (withDomain)
            {
                return identity.Name;
            }
            else
            {
                string name = identity.Name;
                name = name.Substring(name.IndexOf("\\", StringComparison.CurrentCultureIgnoreCase) + 1);
                return name;
            }
        }
    }
}
